package com.itheima.controller;

import com.itheima.health.dto.CheckGroupDTO;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.service.CheckGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "检查组管理开发")  // 作用在类上
public class CheckGroupController {

    @Reference
    private CheckGroupService checkGroupService;


    @GetMapping("checkgroup/findAll")
    public Result findAll(){
        return new Result(checkGroupService.list());
    }

    @GetMapping("checkgroup/findCheckitemInfoByGroupId/{id}")
    public Result findCheckitemInfoByGroupId(@PathVariable("id") Integer id){
        return new Result(checkGroupService.findCheckitemInfoByGroupId(id));
    }

    @PostMapping("checkgroup/findPage")
    @ApiOperation(value = "分页查询", notes = "根据客户端请求，完成分页查询")//   添加业务方法上
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", value = "分页页码", required = true, paramType = "form", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示记录个数", required = true, paramType = "form", dataType = "Integer"),
            @ApiImplicitParam(name = "queryString", value = "查询条件", required = false, paramType = "form", dataType = "String")
    })
    public Result findPage(@RequestBody QueryPageBean queryPageBean) {
        //调用接口中的方法
        return new Result(checkGroupService.findPage(queryPageBean)); //   total  +  List
    }

    //完成检查组管理的添加功能
    //调用自己的方法
    @PostMapping("checkgroup/saveOrUpdate")
    public Result saveOrUpdateCheckGroupInfo(@RequestBody CheckGroupDTO checkGroupDTO) {
        return new Result(checkGroupService.saveOrUpdateCheckGroupInfo(checkGroupDTO));
    }

    @DeleteMapping("checkgroup/deleteCheckgroupById/{id}")
    public Result deleteCheckgroupById(@PathVariable("id") Integer id) {
        return new Result(checkGroupService.deleteCheckgroupById(id));
    }

}








